package com.pignest.hotel.util;

import java.math.BigDecimal;

public class MoneyUtil {

	/**
	 * 分转为元
	 * 
	 * @param money
	 * @return
	 */
	public static double cent2dollar(int money) {
		return  money*1.0 / 100;
	}
	
	/**
	 * 分转为元
	 * 
	 * @param money
	 * @return
	 */
	public static double cent2dollar(Long money) {
		return  money*1.0 / 100;
	}

	/**
	 * 元转为分
	 * 
	 * @param money
	 * @return
	 */
	public static int dollar2cent(int money) {
		return money * 100;
	}
	
	/**
	 * 元转为分
	 * 
	 * @param money
	 * @return
	 */
	public static int dollar2cent(Double money) {
		return  (new Double( money * 100)).intValue();
	}


	public static String toString(Long value) {
		if (value == null) {
			return "";
		}
		return String.valueOf(value*1.0/100);
	}
	
	public static String toString(Integer value) {
		if (value == null) {
			return "";
		}
		return String.valueOf(value*1.0/100);
	}
	public static String toPositiveString(Integer value)
	{
		if(value==null)
		{
			return "";
		}
		if(value<0){
			return String.valueOf(-value*1.0/100);
		}
		return String.valueOf(value*1.0/100);
	}

	public static int toInt(Long value){
		if (value == null) {
			return 0;
		}
		return Integer.valueOf(String.valueOf(value*1/100));
	}

	public static String toString(Double value) {
		if (value == null) {
			return "";
		}
		return String.valueOf(value/100);
	}
	/**4舍5入取整
	 * 
	 * @param value
	 * @return
	 */
	public static int rand(Double value){
		if (value == null) {
			return 0;
		}
		int l=Integer.valueOf(String.valueOf(new BigDecimal(value).setScale(0,BigDecimal.ROUND_HALF_UP)));
		return l;
		
	}
	/**4舍5入取正整
	 * 
	 * @param value
	 * @return
	 */
	public static int randPositive(Double value){
		if (value == null) {
			return 0;
		}
		int l=Integer.valueOf(String.valueOf(new BigDecimal(value).setScale(0,BigDecimal.ROUND_HALF_UP)));
		if(l<0)
			return -l;
		return l;
		
	}
	/**
	 * 取正
	 * **/
	public static int Positive(Integer value)
	{
		if(value==null)
			return 0;
		if(value<0)
			return -value;
		return value;
	}
	public static void main(String[] args) {
		//System.out.println(MoneyUtil.toString(33333));
		//System.out.println(MoneyUtil.rand(15.4));
	}
}
